/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Start.java
 *
 * Created on 01/04/2010, 09:40:14
 */
package br.unb.graphics.start;

/**
 *
 * @author USUARIO
 */
import java.util.ResourceBundle;

import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import br.unb.utils.Resource;

import br.unb.graphics.InterfaceFactory;
import br.unb.graphics.ControlComponent;
import br.unb.graphics.GraphicInterface;
import br.unb.graphics.help.OpenBrowser;

public class Start extends javax.swing.JPanel {

    //private JScrollPane scrollpanel;
    private String stepone = "stepone";
    private String steptwo = "steptwo";
    private String stepthree = "stepthree";
    private String open = "open";
    private String choosegraphic = "chooesegraphic";
    private String traffictable = "traffictable";
    private String syncronyze = "syncronyze";
    private static ResourceBundle resources = Resource.Start;
    private InterfaceFactory ifactory;
    private javax.swing.Action[] actions;
    private boolean generate_traffic;

    /** Creates new form Start */
    public Start() {
        ifactory = new InterfaceFactory(resources);
        actions = ControlComponent.getInstance().getActions();

        initComponents();
        //scrollpanel = new JScrollPane(this);
    }

    //public JScrollPane getPanel() {
    //    return scrollpanel;
    //}

    public void setgenerate_traffic(boolean generate_traffic) {
        this.generate_traffic = generate_traffic;
    }

    private boolean getgenerate_traffic() {
        return this.generate_traffic;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private String PutSpace(String nm) {
        char c[] = nm.toCharArray();
        String mn = new String();
        for (int i = 0; i < c.length; i++) {
            if (c[i] == '_') {
                c[i] = ' ';
            }
            mn += c[i];
        }
        return mn;
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        primeiropassolabel = new javax.swing.JLabel();
        Sincronizarbutton = new javax.swing.JButton();
        Add_new_trafficbutton = new javax.swing.JButton();
        segundopassolabel = new javax.swing.JLabel();
        Tabela_de_trafegosbutton = new javax.swing.JButton();
        terceiropassolabel = new javax.swing.JLabel();
        abrirlabel = new javax.swing.JLabel();
        opened_trafficlabel = new javax.swing.JLabel();
        openbutton = new javax.swing.JButton();
        graficolabel = new javax.swing.JLabel();
        interrogacaobutton = new javax.swing.JButton();
        combobox_graphics = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        helpbutton = new javax.swing.JButton();

        primeiropassolabel.setText("primeiro passo, clique em sincronizar");

        Sincronizarbutton.setText("Sincronizar");
        Sincronizarbutton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SincronizarbuttonActionPerformed(evt);
            }
        });

        Add_new_trafficbutton.setText("Add new traffic");
        Add_new_trafficbutton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Add_new_trafficbuttonActionPerformed(evt);
            }
        });

        segundopassolabel.setText("segundo passo, adicione um novo trafego");

        Tabela_de_trafegosbutton.setText("Tabela de trafegos");
        Tabela_de_trafegosbutton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Tabela_de_trafegosbuttonActionPerformed(evt);
            }
        });

        terceiropassolabel.setText("terceiro passo, clique na tabela de trafegos e depois em play");

        abrirlabel.setText("clique em abrir");

        opened_trafficlabel.setText(" ");

        openbutton.setText("open");
        openbutton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openbuttonActionPerformed(evt);
            }
        });

        graficolabel.setText("escolha o grafico");

        interrogacaobutton.setText("?");
        interrogacaobutton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                interrogacaobuttonActionPerformed(evt);
            }
        });

        combobox_graphics.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        combobox_graphics.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                combobox_graphicsActionPerformed(evt);
            }
        });

        jLabel1.setText(" ");

        jButton1.setText("Se deseja analisar um trafego...");

        jButton2.setText("Se deseja gerar um trafego...");

        helpbutton.setText("Help");
        helpbutton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                helpbuttonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(graficolabel))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(layout.createSequentialGroup()
                                    .addContainerGap()
                                    .addComponent(abrirlabel))
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addContainerGap()
                                        .addComponent(primeiropassolabel))
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addGroup(layout.createSequentialGroup()
                                            .addContainerGap()
                                            .addComponent(segundopassolabel))
                                        .addGroup(layout.createSequentialGroup()
                                            .addGap(10, 10, 10)
                                            .addComponent(terceiropassolabel, javax.swing.GroupLayout.DEFAULT_SIZE, 292, Short.MAX_VALUE))))))
                        .addGap(78, 78, 78)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(Sincronizarbutton)
                                    .addComponent(openbutton))
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(270, 270, 270)
                                        .addComponent(jLabel1)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(opened_trafficlabel))
                                    .addGroup(layout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(interrogacaobutton))))
                            .addComponent(Add_new_trafficbutton)
                            .addComponent(Tabela_de_trafegosbutton)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(combobox_graphics, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(38, 38, 38)
                                .addComponent(helpbutton))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(244, 244, 244)
                        .addComponent(jButton2))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(242, 242, 242)
                        .addComponent(jButton1)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(7, 7, 7)
                .addComponent(jButton2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(primeiropassolabel)
                    .addComponent(Sincronizarbutton)
                    .addComponent(interrogacaobutton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(segundopassolabel)
                    .addComponent(Add_new_trafficbutton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(terceiropassolabel)
                    .addComponent(Tabela_de_trafegosbutton))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(73, 73, 73)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(opened_trafficlabel)
                            .addComponent(jLabel1))
                        .addGap(23, 23, 23)
                        .addComponent(helpbutton))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(24, 24, 24)
                        .addComponent(jButton1)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(abrirlabel)
                            .addComponent(openbutton))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(graficolabel)
                            .addComponent(combobox_graphics, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(39, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void SincronizarbuttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SincronizarbuttonActionPerformed
        GraphicInterface.getInstance().showSyncPanel();
    }//GEN-LAST:event_SincronizarbuttonActionPerformed

    private void interrogacaobuttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_interrogacaobuttonActionPerformed
        String interrogacao = ifactory.getResourceString("?popup");
        JOptionPane.showMessageDialog(null, PutSpace(interrogacao));
    }//GEN-LAST:event_interrogacaobuttonActionPerformed

    private void Add_new_trafficbuttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Add_new_trafficbuttonActionPerformed

        GraphicInterface.getInstance().showNewTrafficPanel();
    }//GEN-LAST:event_Add_new_trafficbuttonActionPerformed

    private void Tabela_de_trafegosbuttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Tabela_de_trafegosbuttonActionPerformed
        GraphicInterface.getInstance().showTrafficTable();
    }//GEN-LAST:event_Tabela_de_trafegosbuttonActionPerformed

    private void openbuttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openbuttonActionPerformed
        actions[8].actionPerformed(evt);
        graficolabel.setVisible(true);
        combobox_graphics.setVisible(true);
    }//GEN-LAST:event_openbuttonActionPerformed

    private void combobox_graphicsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_combobox_graphicsActionPerformed
        /*if (combobox_graphics.getSelectedIndex() == 1) {
            GraphicInterface.getInstance().loadDelayChart();
        }
        if (combobox_graphics.getSelectedIndex() == 2) {
            GraphicInterface.getInstance().loadJitterChart();
        }
        if (combobox_graphics.getSelectedIndex() == 3) {
            GraphicInterface.getInstance().loadBandwidthChart();
        }
        if (combobox_graphics.getSelectedIndex() == 4) {
            GraphicInterface.getInstance().loadLossChart();
        }*/
    }//GEN-LAST:event_combobox_graphicsActionPerformed

    private void helpbuttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_helpbuttonActionPerformed
        /*	OpenBrowser     browser = new OpenBrowser();

        String URL = ("file:///"+System.getProperty("user.dir") + "/help/help.html");
        String URLSend = browser.URLCaracteresInvalidos(URL);

        browser.OpenBrowser(URLSend);*/

        OpenBrowser browser = new OpenBrowser();
        browser.OpenHelp("help.html");

    }//GEN-LAST:event_helpbuttonActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Add_new_trafficbutton;
    private javax.swing.JButton Sincronizarbutton;
    private javax.swing.JButton Tabela_de_trafegosbutton;
    private javax.swing.JLabel abrirlabel;
    private javax.swing.JComboBox combobox_graphics;
    private javax.swing.JLabel graficolabel;
    private javax.swing.JButton helpbutton;
    private javax.swing.JButton interrogacaobutton;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JButton openbutton;
    private javax.swing.JLabel opened_trafficlabel;
    private javax.swing.JLabel primeiropassolabel;
    private javax.swing.JLabel segundopassolabel;
    private javax.swing.JLabel terceiropassolabel;
    // End of variables declaration//GEN-END:variables
}
